

global CPI2010_15 = 1.0867

********************
*** Cost Summary ***
********************
{
use ".\statadata\Annual_Summary_output", clear
drop if year==.
reshape long Nbene_ MCR_payment_ BENE_payment_, i(year) j(type) string

replace MCR_payment_ = MCR_payment_/1000000000
replace BENE_payment_ = BENE_payment_/1000000000
replace Nbene_ = Nbene_/1000000

reshape wide Nbene_ MCR_payment_ BENE_payment_, i(type) j(year)

gen r = .
replace r = 1 if type=="AB"
replace r = 2 if type=="A"
replace r = 3 if type=="IP"
replace r = 4 if type=="SNF"
replace r = 5 if type=="HHA_A"
replace r = 6 if type=="hospice"
replace r = 7 if type=="B"
replace r = 8 if type=="carrier"
replace r = 9 if type=="OP"
replace r = 10 if type=="HHA_B"
replace r = 11 if type=="DME"
replace r = 11.2 if type=="nCBP"
replace r = 11.1 if type=="CBP"
replace r = 12 if type=="pde"
replace r = 13 if type=="ABD"

sort r
drop r

foreach ver of varlist Nbene* MCR_payment* BENE_payment* {
	replace `ver' = `ver'*5
}
replace MCR_payment_2010 = MCR_payment_2010*$CPI2010_15
replace BENE_payment_2010 = BENE_payment_2010*$CPI2010_15

gen total_per_2010 = (MCR_payment_2010+BENE_payment_2010) / Nbene_2010
gen total_per_2015 = (MCR_payment_2015+BENE_payment_2015) / Nbene_2015

format Nbene* MCR_payment* BENE_payment* total_per* %12.1f
order type *2010 *2015
export excel using "$resdir\Table.xls", sheet("TableA1_costsummary") sheetreplace firstrow(variable)
}



***************************
*** Top 20 DME Products ***
***************************
{
use ".\statadata\dme_total_matched", clear
gen year = year(clm_thru_dt)
keep if year==2010 | year==2015

collapse (sum) payment = line_alowd_chrg_amt, by(hcpcs_cd mod1 mod2 year category nmo_x r1_x r2_x r1rc_x)
replace payment = payment/1000000*5
format payment %12.1f

gen CBP = ""
replace CBP = "R1, NMO" if nmo_x==1
replace CBP = "R1, R2, R1RC" if r1_x==1 & r2_x==1 & r1rc_x==1
replace CBP = "R2, R1RC" if r1_x==. & r2_x==1 & r1rc_x==1
replace CBP = "R1RC" if r1_x==. & r2_x==. & r1rc_x==1
replace CBP = "R1" if r1_x==1 & r2_x==. & r1rc_x==.
drop nmo_x r1_x r2_x r1rc_x

reshape wide payment, i(hcpcs_cd mod1 mod2 CBP category_x) j(year)

gsort -payment2010
drop if inlist(hcpcs_cd,"66984","J7626","J3285","Q0513")
gen rank = _n
gen lead = .
replace lead = 1 if hcpcs_cd=="B4035" // Enteral Nutrient
replace lead = 1 if hcpcs_cd=="E0260" & mod1=="RR" // Hospital bed
replace lead = 1 if hcpcs_cd=="E0277" & mod1=="RR" // Mattress
replace lead = 1 if hcpcs_cd=="E0163" & mod1=="NU" // Commode chair
replace lead = 1 if hcpcs_cd=="E0630" & mod1=="RR" // Patient lift
replace lead = 1 if hcpcs_cd=="A4595" // TENS
replace lead = 1 if hcpcs_cd=="E0143" & mod1=="NU" // Walker
replace lead = 1 if hcpcs_cd=="E2402" & mod1=="RR" // NPWT
replace lead = 1 if hcpcs_cd=="E1390" & mod1=="RR" // Oxygen concentrator
replace lead = 1 if hcpcs_cd=="E0601" & mod1=="RR" // CPAP
replace lead = 1 if hcpcs_cd=="E0570" & mod1=="RR" // Nebulizer
replace lead = 1 if hcpcs_cd=="E0784" & mod1=="RR" // Infusion pumps
replace lead = 1 if hcpcs_cd=="K0823" & mod1=="RR" // Wheelchair
replace lead = 1 if hcpcs_cd=="A4253" & mod1=="NU" & mod2=="KL" // Diabetes
keep if _n<=20 | lead==1

* Format
replace hcpcs_cd = hcpcs_cd+"-"+mod1 if mod1!="" & mod2==""
replace hcpcs_cd = hcpcs_cd+"-"+mod1+"-"+mod2 if mod1!="" & mod2!=""
drop mod1 mod2

gen desc = ""
replace desc = "Oxygen concentrator" if hcpcs_cd=="E1390-RR"
replace desc = "Diabetic test strips, mail" if hcpcs_cd=="A4253-NU-KL"
replace desc = "Diabetic test strips" if hcpcs_cd=="A4253-NU"
replace desc = "Power wheelchair, new" if hcpcs_cd=="K0823-NU"
replace desc = "Hospital bed" if hcpcs_cd=="E0260-RR"
replace desc = "CPAP device" if hcpcs_cd=="E0601-RR"
replace desc = "Enteral feeding supply kit" if hcpcs_cd=="B4035"
replace desc = "Portable oxygen system" if hcpcs_cd=="E0431-RR"
replace desc = "Diabtic shoe" if hcpcs_cd=="A5500"
replace desc = "NPWT pump" if hcpcs_cd=="E2402-RR"
replace desc = "Lancets, mail" if hcpcs_cd=="A4259-KL"
replace desc = "Nasal application device" if hcpcs_cd=="A7034-NU"
replace desc = "Enteral formula, metabolic" if hcpcs_cd=="B4154"
replace desc = "Respiratory assist device" if hcpcs_cd=="E0470-RR"
replace desc = "CPAP full face mask" if hcpcs_cd=="A7030-NU"
replace desc = "Enteral formula, complete" if hcpcs_cd=="B4150"
replace desc = "Diabtic shoe, customed" if hcpcs_cd=="A5513"
replace desc = "Walker" if hcpcs_cd=="E0143-NU"
replace desc = "Diabtic shoe, direct formed" if hcpcs_cd=="A5512"
replace desc = "Osteogenesis stimulator" if hcpcs_cd=="E0748-NU"
replace desc = "Pressure-reducing mattress" if hcpcs_cd=="E0277-RR"
replace desc = "Nebulizer" if hcpcs_cd=="E0570-RR"
replace desc = "Commode chair" if hcpcs_cd=="E0163-NU"
replace desc = "External infusion pump" if hcpcs_cd=="E0784-RR"
replace desc = "Patient lift" if hcpcs_cd=="E0630-RR"
replace desc = "TENS supplies" if hcpcs_cd=="A4595"
replace desc = "Power wheelchair, rent" if hcpcs_cd=="K0823-RR"
replace desc = desc+"*" if lead==1

gen FFS_2010 = .
replace FFS_2010 = 173.9 if hcpcs_cd=="E1390-RR"
replace FFS_2010 = 32.5 if hcpcs_cd=="A4253-NU-KL"
replace FFS_2010 = 37.7 if hcpcs_cd=="A4253-NU"
replace FFS_2010 = 364.8/0.1 if hcpcs_cd=="K0823-NU"
replace FFS_2010 = 127.1 if hcpcs_cd=="E0260-RR"
replace FFS_2010 = 96.8 if hcpcs_cd=="E0601-RR"
replace FFS_2010 = 11.3 if hcpcs_cd=="B4035"
replace FFS_2010 = 28.8 if hcpcs_cd=="E0431-RR"
replace FFS_2010 = 66.8 if hcpcs_cd=="A5500"
replace FFS_2010 = 1559.3 if hcpcs_cd=="E2402-RR"
replace FFS_2010 = 10.6 if hcpcs_cd=="A4259-KL"
replace FFS_2010 = 106.9 if hcpcs_cd=="A7034-NU"
replace FFS_2010 = 1.18 if hcpcs_cd=="B4154"
replace FFS_2010 = 219.2 if hcpcs_cd=="E0470-RR"
replace FFS_2010 = 171.4 if hcpcs_cd=="A7030-NU"
replace FFS_2010 = 0.65 if hcpcs_cd=="B4150"
replace FFS_2010 = 40.7 if hcpcs_cd=="A5513"
replace FFS_2010 = 105.7 if hcpcs_cd=="E0143-NU"
replace FFS_2010 = 27.2 if hcpcs_cd=="A5512"
replace FFS_2010 = 4107.6 if hcpcs_cd=="E0748-NU"
replace FFS_2010 = 627.4 if hcpcs_cd=="E0277-RR"
replace FFS_2010 = 16.9 if hcpcs_cd=="E0570-RR"
replace FFS_2010 = 112.6 if hcpcs_cd=="E0163-NU"
replace FFS_2010 = 440.1 if hcpcs_cd=="E0784-RR"
replace FFS_2010 = 102.6 if hcpcs_cd=="E0630-RR"
replace FFS_2010 = 30.2 if hcpcs_cd=="A4595"
replace FFS_2010 = 364.8 if hcpcs_cd=="K0823-RR"


gen FFS_2015 = .
replace FFS_2015 = 180.9 if hcpcs_cd=="E1390-RR"
replace FFS_2015 = 34.4 if hcpcs_cd=="A4253-NU-KL"
replace FFS_2015 = 10.4 if hcpcs_cd=="A4253-NU"
replace FFS_2015 = . if hcpcs_cd=="K0823-NU"
replace FFS_2015 = 134.4 if hcpcs_cd=="E0260-RR"
replace FFS_2015 = 102.4 if hcpcs_cd=="E0601-RR"
replace FFS_2015 = 12.0 if hcpcs_cd=="B4035"
replace FFS_2015 = 30.4 if hcpcs_cd=="E0431-RR"
replace FFS_2015 = 70.6 if hcpcs_cd=="A5500"
replace FFS_2015 = 1648.3 if hcpcs_cd=="E2402-RR"
replace FFS_2015 = 11.15 if hcpcs_cd=="A4259-KL"
replace FFS_2015 = 113.0 if hcpcs_cd=="A7034-NU"
replace FFS_2015 = 1.25 if hcpcs_cd=="B4154"
replace FFS_2015 = 231.75 if hcpcs_cd=="E0470-RR"
replace FFS_2015 = 181.2 if hcpcs_cd=="A7030-NU"
replace FFS_2015 = 0.7 if hcpcs_cd=="B4150"
replace FFS_2015 = 43.0 if hcpcs_cd=="A5513"
replace FFS_2015 = 111.7 if hcpcs_cd=="E0143-NU"
replace FFS_2015 = 28.8 if hcpcs_cd=="A5512"
replace FFS_2015 = 4342.1 if hcpcs_cd=="E0748-NU"
replace FFS_2015 = 663.2 if hcpcs_cd=="E0277-RR"
replace FFS_2015 = 17.9 if hcpcs_cd=="E0570-RR"
replace FFS_2015 = 119.1 if hcpcs_cd=="E0163-NU"
replace FFS_2015 = 465.2 if hcpcs_cd=="E0784-RR"
replace FFS_2015 = 108.5 if hcpcs_cd=="E0630-RR"
replace FFS_2015 = 32.0 if hcpcs_cd=="A4595"
replace FFS_2015 = 578.5 if hcpcs_cd=="K0823-RR"


gen SPA_2015 = .
replace SPA_2015 = 93.3 if hcpcs_cd=="E1390-RR"
replace SPA_2015 = 10.41 if hcpcs_cd=="A4253-NU-KL"
replace SPA_2015 = . if hcpcs_cd=="A4253-NU"
replace SPA_2015 = . if hcpcs_cd=="K0823-NU"
replace SPA_2015 = 70.6 if hcpcs_cd=="E0260-RR"
replace SPA_2015 = 47.0 if hcpcs_cd=="E0601-RR"
replace SPA_2015 = 6.0 if hcpcs_cd=="B4035"
replace SPA_2015 = 19.4 if hcpcs_cd=="E0431-RR"
replace SPA_2015 = . if hcpcs_cd=="A5500"
replace SPA_2015 = 817.9 if hcpcs_cd=="E2402-RR"
replace SPA_2015 = 1.65 if hcpcs_cd=="A4259-KL"
replace SPA_2015 = 62.8 if hcpcs_cd=="A7034-NU"
replace SPA_2015 = 0.7 if hcpcs_cd=="B4154"
replace SPA_2015 = 117.0 if hcpcs_cd=="E0470-RR"
replace SPA_2015 = 101.9 if hcpcs_cd=="A7030-NU"
replace SPA_2015 = 0.4 if hcpcs_cd=="B4150"
replace SPA_2015 = . if hcpcs_cd=="A5513"
replace SPA_2015 = 53.7 if hcpcs_cd=="E0143-NU"
replace SPA_2015 = . if hcpcs_cd=="A5512"
replace SPA_2015 = . if hcpcs_cd=="E0748-NU"
replace SPA_2015 = 239.3 if hcpcs_cd=="E0277-RR"
replace SPA_2015 = 10.2 if hcpcs_cd=="E0570-RR"
replace SPA_2015 = 63.8 if hcpcs_cd=="E0163-NU"
replace SPA_2015 = 380.2 if hcpcs_cd=="E0784-RR"
replace SPA_2015 = 63.3 if hcpcs_cd=="E0630-RR"
replace SPA_2015 = 15.2 if hcpcs_cd=="A4595"
replace SPA_2015 = 297.6 if hcpcs_cd=="K0823-RR"

format payment* FFS* SPA* %12.1f
order rank hcpcs_cd desc CBP FFS_2010 FFS_2015 SPA_2015 payment2010 payment2015 
keep rank hcpcs_cd desc CBP FFS_2010 FFS_2015 SPA_2015 payment2010 payment2015 

replace FFS_2010 = FFS_2010*$CPI2010_15
replace payment2010 = payment2010*$CPI2010_15

export excel using "$resdir\Table.xls", sheet("TableA2_top20DME") sheetreplace firstrow(variable)

}



*******************
*** CBA Summary ***
*******************

* Population (Part B non-HMO months)
{
use ".\statadata\mbsf", clear
keep if year>=2009
gen ZIP = substr(zip_cd,1,5)
drop zip_cd
merge m:1 ZIP using ".\raw\ZIP_CBA_CBSA.dta", keep(1 3) nogen
foreach i in "01" "02" "03" "04" "05" "06" "07" "08" "09" "10" "11" "12" {
    gen enroll`i' = 1 if inlist(mdcr_entlmt_buyin_ind_`i',"2","3","B","C") & hmo_ind_`i'=="0"
	gen enroll`i'_dual = 1 if inlist(mdcr_entlmt_buyin_ind_`i',"B","C") & hmo_ind_`i'=="0"
}
egen enroll_Q1 = rowtotal(enroll01 enroll02 enroll03)
egen enroll_Q2 = rowtotal(enroll04 enroll05 enroll06)
egen enroll_Q3 = rowtotal(enroll07 enroll08 enroll09)
egen enroll_Q4 = rowtotal(enroll10 enroll11 enroll12)
egen dual_Q1 = rowtotal(enroll01_dual enroll02_dual enroll03_dual)
egen dual_Q2 = rowtotal(enroll04_dual enroll05_dual enroll06_dual)
egen dual_Q3 = rowtotal(enroll07_dual enroll08_dual enroll09_dual)
egen dual_Q4 = rowtotal(enroll10_dual enroll11_dual enroll12_dual)
drop *ind* enroll01-enroll12 enroll01_dual-enroll12_dual
format *mons %2.0f
gen ssdi = (bene_entlmt_rsn_curr=="1" | bene_entlmt_rsn_curr=="3")
keep bene_id year ZIP geo_id cba_round age gender ssdi enroll_Q* dual_Q*
compress
save ".\temp\mbsf", replace

* Per capita denominator - Full 3 months Part B, all dual & all nondual
forvalues i = 1/4 {
	gen pop_FFS`i' = 1 if enroll_Q`i'==3 
	gen pop_FFSdual`i' = 1 if enroll_Q`i'==3 & dual_Q`i'==3
	gen pop_FFSnondual`i' = 1 if enroll_Q`i'==3 & dual_Q`i'==0
}
egen temp = rowtotal(pop_FFS1 pop_FFS2 pop_FFS3 pop_FFS4)
bysort bene_id: egen enroll28 = sum(temp)
gen pop_FFS_full28Q = 1 if enroll28==28
preserve
collapse (sum) pop_FFS*, by(geo_id year)
reshape long pop_FFS pop_FFSdual pop_FFSnondual, i(geo_id year pop_FFS_full28Q) j(qtr)
gen yq = yq(year,qtr)
drop if geo_id==""
tempfile temp 
save `temp'
restore

* Population weights - FFS population 2010, allow for partial enrollments
keep if year==2010
drop if geo_id==""
egen enroll = rowtotal(enroll_Q1 enroll_Q2 enroll_Q3 enroll_Q4)
egen dual = rowtotal(dual_Q1 dual_Q2 dual_Q3 dual_Q4)
replace enroll = enroll/12 
replace dual = dual/12 
collapse (sum) enroll dual, by(geo_id)
rename enroll pop_FFS_2010
rename dual pop_FFSdual_2010
gen pop_FFSnondual_2010 = pop_FFS_2010-pop_FFSdual_2010
merge 1:m geo_id using `temp', nogen
save ".\temp\population", replace
}

* Summary by GEO_ID
{
use ".\raw\ZIP_CBA_CBSA.dta", clear
keep geo_id cba_round
duplicates drop
merge 1:1 geo_id using ".\statadata\geo_sum_2010", nogen
drop if geo_id==""
drop if cba_round==.

gen insample = 1 if cba_round>0 | (cba_round==0 & n_mcrffs>=9000 & n_mcrffs!=.)
preserve
keep geo_id insample
merge 1:m geo_id using ".\raw\ZIP_CBA_CBSA.dta", nogen
save ".\temp\ZIP_CBA_CBSA.dta", replace
restore

* Summary
preserve
gen n_geo = 1
collapse (count) n_geo (mean) age male ssdi dual payment payment_dme has_dme has_dmecbp [aw=n_mcrffs], by(cba_round)
tempfile temp
save `temp'
restore

egen total = sum(n_mcrffs)
gen share_mcrffs = n_mcrffs/total*100
collapse (mean) n_mcrffs (sum) share_mcrffs, by(cba_round)
merge 1:1 cba_round using `temp', nogen

order cba_round n_geo n_mcrffs share_mcrffs age male ssdi dual payment payment_dme has_dme has_dmecbp
xpose, clear varname
order _varname
replace _varname = "# MCR FFS Population (2010)" if _varname=="n_mcrffs"
replace _varname = "% MCR FFS Population (2010)" if _varname=="share_mcrffs"
replace _varname = "Age" if _varname=="age"
replace _varname = "Male" if _varname=="male"
replace _varname = "SSDI" if _varname=="ssdi"
replace _varname = "Dual Eligible" if _varname=="dual"
replace _varname = "Average MCR Spending" if _varname=="payment"
replace _varname = "Average MCR DME Spending" if _varname=="payment_dme"
replace _varname = "Has DME Claim" if _varname=="has_dme"
replace _varname = "Has CBP DME Claim" if _varname=="has_dmecbp"
replace _varname = "# Area" if _varname=="n_geo"
export excel using $resdir\Table.xls, sheet("Table1_GeoSummary") sheetreplace

}


